<?php
/**
 * oscshop2 B2C电子商务系统
 *
 * ==========================================================================
 * @link      http://www.oscshop.cn/
 * @copyright Copyright (c) 2015-2017 oscshop.cn. 
 * @license   http://www.oscshop.cn/license.html License
 * ==========================================================================
 *
 * @author    
 *
 * 预积分  2017-03-11 
 * 
 */
namespace osc\mobile\controller;
use osc\common\controller\Base;
use \think\Db;
use think\Request;
class Prepoints extends Base
{
	
	function check_login(){
		
		$uid=is_login();
		
		if(!$uid){			
			$this->redirect('login/login');					
		}

		$username = session('username');
		
		if(!$username)
		{
			$this->redirect('login/login');					
		}
		return $uid;
	}
	
	function index(){
		
		$uid=$this->check_login();
		$username = session('username');
		if(!$username)
		{
			$this->redirect('login/login');					
		}
		$start = input('param.start');
		$end = input('param.end');
		if($start && $end){
			$map = [
					'uid' => $uid,
					'creat_time' => array(['>',strtotime($start)],['<',strtotime($end)])
			];
			$list = Db::name('prepoint')->where($map)->paginate(2,false, [
					'query' => Request::instance()->param(),//不丢失已存在的url参数
			]);
		}else{

			$list = Db::name('prepoint')
					->where(array('uid' => $uid))
					->paginate(2);
		}
		$page=$list->render(); //获取分页
//		$list = Db::name('prepoint')->where(array('uid'=>$uid))->select();

		$user_info = Db::name('member')->where(array('uid'=>$uid))->find();
		$this->assign('user_info',$user_info);
		$this->assign('list',$list);
		$this->assign('start',$start);
		$this->assign('end',$end);
		$this->assign('page',$page);
		$this->assign('empty',"<span style='margin-left:20px;'>没有数据</span>");
				
		$this->assign('top_title','我的银豆');
		$this->assign('SEO',['title'=>'我的银豆-'.config('SITE_TITLE')]);
				
		return $this->fetch();
	}	
	
}